package com.wc.alorithm_blue_bridge._枚举.拯救美猴王;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/7/29 16:29
 * @description https://www.lanqiao.cn/problems/19750/learning/?contest_id=197
 */
public class Main {
    /**
     * 思路：
     * 枚举计数就好了
     * 枚举C
     * 枚举A, 找 B = C - A 的个数
     * 枚举D, 找 E = C - D 的个数
     * 相乘就好了
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 2010;
    static int[] a = new int[N];
    static int[] numL = new int[N], numR = new int[N];
    static int n;

    public static void main(String[] args) {
        n = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            a[i] = sc.nextInt();
            if (i > 3) numR[a[i]]++;
            else if (i < 3) numL[a[i]]++;
        }
        long res = 0;
        // 枚举C
        for (int i = 3; i <= n - 2; i++) {
            long resL = 0, resR = 0;
            // 枚举A
            for (int j = 1; j < i; j++) {
                numL[a[j]]--;
                if (a[i] - a[j] >= 0) resL += numL[a[i] - a[j]];
                numL[a[j]]++;
            }
            // 枚举D
            for (int j = i + 1; j <= n; j++) {
                numR[a[j]]--;
                if (a[i] - a[j] >= 0) resR += numR[a[i] - a[j]];
                numR[a[j]]++;
            }
            // 相乘
            res += (resL / 2) * (resR / 2);
            numL[a[i]]++;
            numR[a[i + 1]]--;
        }
        out.println(res);
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
